package com.example.demo.vo;

import com.example.demo.constants.Constants;
import lombok.Data;
import org.springframework.http.HttpStatus;

import java.io.Serializable;

/**
 * 返回值.
 * @author lei
 */
@Data
public class Response<T> implements Serializable {

    private static final long serialVersionUID = -526324944915280489L;

    private String code;
    private String msg;
    private T data;

    public static Response ok() {
        Response r = new Response();
        r.setCode(Constants.SUCCESS);
        return r;
    }

    public static Response ok(Object object) {
        Response r = new Response();
        r.setCode(Constants.SUCCESS);
        r.setData(object);
        return r;
    }

    public static Response ok(String msg, Object object) {
        Response r = new Response();
        r.setCode(Constants.SUCCESS);
        r.setMsg(msg);
        r.setData(object);
        return r;
    }

    public static Response fail(String code, String msg) {
        Response r = new Response();
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }

    public static Response fail(HttpStatus httpStatus, String msg) {
        Response r = new Response();
        r.setCode(httpStatus.value() + "");
        r.setMsg(msg);
        return r;
    }

    public static Response fail(String code, String msg, Object object) {
        Response r = new Response();
        r.setCode(code);
        r.setMsg(msg);
        r.setData(object);
        return r;
    }


}
